package com.example.myzhugezhaofang.adapter;

import android.content.Context;
import android.view.View;
import android.widget.ImageView;
import android.widget.TextView;

import com.bumptech.glide.Glide;
import com.example.mvplibrary.adapter.BaseAdapter;
import com.example.mvplibrary.adapter.BaseViewHolder;
import com.example.myzhugezhaofang.R;
import com.example.myzhugezhaofang.bean.ConsultingBean;

import java.util.List;

/**
 * 作者：朱勇闯
 * data : 2021/4/16  15:41
 * 作用： xxxx
 */
public class ConsultingAdapter extends BaseAdapter<ConsultingBean.ListBean> {
    public ItemListener itemListener;

    public void setItemListener(ItemListener itemListener) {
        this.itemListener = itemListener;
    }

    public ConsultingAdapter(List<ConsultingBean.ListBean> datas, Context context, int layoutId) {
        super(datas, context, layoutId);
    }

    @Override
    protected void bindData(BaseViewHolder holder, ConsultingBean.ListBean listBean, int position) {
        TextView text1 = holder.getView(R.id.tv_consulting_1);
        TextView text21 = holder.getView(R.id.tv_consulting_21);
        TextView text22 = holder.getView(R.id.tv_consulting_22);
        TextView text23 = holder.getView(R.id.tv_consulting_23);
        ImageView small = holder.getView(R.id.iv_consulting_small);
        ImageView big = holder.getView(R.id.iv_consulting_big);

        text1.setText(listBean.getTitle());
        if (listBean.getNews_label().equals("3")) {
            text21.setText("置顶");
            text21.setPadding(5, 5, 5, 5);
        }
        text22.setText(listBean.getSource_info().getSource_name());


        if (listBean.getThumb().size() != 0) {
            Glide.with(context).load(listBean.getThumb().get(0)).into(big);
        } else {
            Glide.with(context).load(listBean.getThumb()).into(big);
            text1.setWidth(2200);
        }
        Glide.with(context).load(listBean.getSource_info().getSource_img()).into(small);

        holder.itemView.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                itemListener.onItemClickListener(position);
            }
        });
    }

    public interface ItemListener {
        void onItemClickListener(int pos);
    }
}
